class Solution {
    public boolean backspaceCompare(String s, String t) {
        return changeStr(s).equals(changeStr(t));
    }
        public String changeStr(String s){
            StringBuffer ret = new StringBuffer();
            for(int i=0;i<s.length();i++){
                char ch=s.charAt(i);
                if(ch!='#'){
                    ret.append(ch);
                }else{
                    if(ret.length()>0)
                        ret.deleteCharAt(ret.length()-1);
                }
            }
            return ret.toString();
        }   
}